﻿Imports DTO
Imports DAO.DataProvider
Public Class ThuocDAO
    Public Function INSERT(ByVal thuoc As ThuocDTO) As Integer
        Dim DTP As New DataProvider()
        Dim cnn As New OleDb.OleDbConnection()
        cnn = DTP.ConnectDB()
        cnn.Open()
        Dim query As String
        query = " insert into THUOC(TenThuoc,DonGia) values (@tenthuoc,@dongia) "
        Dim cmd As New OleDb.OleDbCommand(query, cnn)
        'dung parameter truyen du lieu
        Dim para As OleDb.OleDbParameter
        para = cmd.Parameters.Add("@tenthuoc", OleDb.OleDbType.VarChar)
        para.Value = thuoc.TenThuoc
        para = cmd.Parameters.Add("@dongia", OleDb.OleDbType.BigInt)
        para.Value = thuoc.DONGIA
        Dim i As Integer
        i = cmd.ExecuteNonQuery()
        cnn.Close()
        If (i > 0) Then
            Return 1
        Else
            Return 0
        End If
    End Function
    'thuc hien chuc nang update
    Public Function UPDATE(ByVal thuoc As ThuocDTO) As Integer
        Dim DTP As New DataProvider()
        Dim cnn As New OleDb.OleDbConnection()
        cnn = DTP.ConnectDB()
        cnn.Open()
        Dim query As String
        query = " update THUOC set(TenThuoc=@tenthuoc,DonGia=@dongia) where MaThuoc=@mathuoc "
        Dim cmd As New OleDb.OleDbCommand(query, cnn)
        'dung parameter truyen du lieu
        Dim para As OleDb.OleDbParameter
        para = cmd.Parameters.Add("@tenthuoc", OleDb.OleDbType.VarChar)
        para.Value = thuoc.TenThuoc
        para = cmd.Parameters.Add("@dongia", OleDb.OleDbType.BigInt)
        para.Value = thuoc.DONGIA
        para = cmd.Parameters.Add("@mathuoc", OleDb.OleDbType.BigInt)
        para.Value = thuoc.MaThuoc
        Dim i As Integer
        i = cmd.ExecuteNonQuery()
        cnn.Close()
        If (i > 0) Then
            Return 1
        Else
            Return 0
        End If
    End Function
    'thuc hien chuc nang DELLETE
    Public Function DELETE(ByVal thuoc As ThuocDTO) As Integer
        Dim DTP As New DataProvider()
        Dim cnn As New OleDb.OleDbConnection()
        cnn = DTP.ConnectDB()
        cnn.Open()
        Dim query As String
        query = " DELETE from THUOC where MaThuoc=@mathuoc "
        Dim cmd As New OleDb.OleDbCommand(query, cnn)
        'dung parameter truyen du lieu
        Dim para As OleDb.OleDbParameter

        para = cmd.Parameters.Add("@mathuoc", OleDb.OleDbType.BigInt)
        para.Value = thuoc.MaThuoc
        Dim i As Integer
        i = cmd.ExecuteNonQuery()
        cnn.Close()
        If (i > 0) Then
            Return 1
        Else
            Return 0
        End If
    End Function


End Class
